<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML" 4.01"//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- Created: September 7, 2001-->
<!--
$Id: TubeModify.php,v 1.3 2001/11/02 19:12:43 eugenem Exp $
$Header: /export/home/eugenem/public_html/ComplianceReports/RCS/TubeModify.php,v 1.3 2001/11/02 19:12:43 eugenem Exp $
$Log: TubeModify.php,v $
Revision 1.3  2001/11/02 19:12:43  eugenem
Moved HTTP_*_VARS processing to dbc.inc

Revision 1.2  2001/11/02 15:01:23  eugenem
Moved database connect statements to a separate file.

Revision 1.1  2001/09/11 12:45:02  eugenem
Initial revision


-->

<html>
<head>
<title>Radiological Equipment Database</title>
<meta name="author" content="Eugene Mah">
<link rev="made" href="mailto:eugenem@ix.netcom.com">
<link rev="home" href="http://home.netcom.com/~eugenem/">
<meta name="description" content="">
<meta name="Keywords" content="">
<meta name="Reply-to" content="eugenem@ix.netcom.com">
<META http-equiv="PICS-Label" content='(PICS-1.1 "http://www.classify.org/safesurf/" l r (SS~~0001))'>
<?PHP
require('functions.inc');
require('dbc.inc');

?>
</head>

<body>
<h1>Radiological Equipment Database</h1>
<?PHP
if (isset($TubeID) && empty($change)) {
  /*
    Machine has been selected.  Display a form showing the current machine
    info and text fields where changes can be entered
  */

  $query = "SELECT TubeID,Description,HousingManufID,HousingManuf.Manufacturer as HsgManuf,
            HousingModel,HousingSN,InsertManufID,InsertManuf.Manufacturer as InsManuf,InsertModel,
            InsertSN,Tubes.ManufDate,LFS,MFS,SFS,Tubes.Notes,Tubes.InstallDate,Tubes.RemoveDate,Tubes.Status as TubeStatus,
            IF(Tubes.ManufDate<>\"0000-00-00\",
              PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM Tubes.ManufDate))/12,
            IF(Tubes.InstallDate<>\"0000-00-00\",
              PERIOD_DIFF(EXTRACT(YEAR_MONTH FROM CURRENT_DATE),EXTRACT(YEAR_MONTH FROM Tubes.InstallDate))/12,
              \"N/A\")) AS Age 
            FROM Machines
            LEFT JOIN Tubes USING (MachineID),Manufacturer as HousingManuf, Manufacturer AS InsertManuf 
            WHERE TubeID=$TubeID 
            AND HousingManufID=HousingManuf.ManufacturerID 
            AND InsertManufID=InsertManuf.ManufacturerID";
  $result = mysql_query($query)
    or die ("<p>Unable to update status: $query</p>\n");

  $row = mysql_fetch_array($result);

  $manuf = mysql_query("select * from Manufacturer order by Manufacturer");
  $description = mysql_query("select MachineID,Description from Machines where Status=\"Active\" order by Description");
?>
<form action="TubeModify.php" method="POST">
<input type="HIDDEN" name="change" value="1">
<input type="HIDDEN" name="TubeID" value="<?PHP echo $TubeID; ?>">
<h2><?PHP echo $row['Description']; ?></h2>
<h3>Tube Housing</h3>
<table border=1 cellpadding=3>
  <tr>
    <th>Hsg Manufacturer</th><th>Hsg Model</th><th>Hsg Serial Number</th>
  </tr>
  <tr>
    <td><?PHP echo $row['HsgManuf']; ?></td>
    <td><?PHP echo $row['HousingModel']; ?></td>
    <td><?PHP echo $row['HousingSN']; ?></td>
  </tr>
  <tr>
    <td><?PHP echo listbox_field($manuf,"HousingManufID",$row['HousingManufID']); ?></td>
    <td><input type="TEXT" name="HousingModel" size="20" value="<?PHP echo $row['HousingModel']; ?>"></td>
    <td><input type="TEXT" name="HousingSN" size="20" value="<?PHP echo $row['HousingSN']; ?>"></td>
  </tr>
</table>

<h3>Tube Insert</h3>
<table border=1 cellpadding=3>
  <tr>
    <th>Ins Manufacturer</th><th>Ins Model</th><th>Ins Serial Number</th>
  </tr>
  <tr>
    <td><?PHP echo $row['InsManuf']; ?></td>
    <td><?PHP echo $row['InsertModel']; ?></td>
    <td><?PHP echo $row['InsertSN']; ?></td>
  </tr>
  <tr>
    <td><?PHP mysql_data_seek($manuf,0); echo listbox_field($manuf,"InsManufID",$row['InsertManufID']); ?></td>
    <td><input type="TEXT" name="InsertModel" size="20" value="<?PHP echo $row['InsertModel']; ?>"></td>
    <td><input type="TEXT" name="InsertSN" size="20" value="<?PHP echo $row['InsertSN']; ?>"></td>
  </tr>
</table>

<h3>Focal spot</h3>
<table border=1 cellpadding=3>
  <tr>
    <th>Large focus</th><th>Medium focus</th><th>Small focus</th>
  </tr>
  <tr>
    <td><input type="TEXT" name="LFS" size="4" value="<?PHP echo $row['LFS']; ?>"></td>
    <td><input type="TEXT" name="MFS" size="4" value="<?PHP echo $row['MFS']; ?>"></td>
    <td><input type="TEXT" name="SFS" size="4" value="<?PHP echo $row['SFS']; ?>"></td>
</table>

<h3>Dates</h3>
<table border=1 cellpadding=3>
  <tr>
    <th>Manuf Date</th><th>Install Date</th><th>Remove Date</th><th>Age</th><th>Active</th>
  </tr>
  <tr>
    <td><input type="TEXT" name="ManufDate" size="10" value="<?PHP echo $row['ManufDate']; ?>"></td>
    <td><input type="TEXT" name="InstallDate" size="10" value="<?PHP echo $row['InstallDate']; ?>"></td>
    <td><input type="TEXT" name="RemoveDate" size="10" value="<?PHP echo $row['RemoveDate']; ?>"></td>
    <td><?PHP echo $row['Age']; ?></td>
    <td>
      <select name="Status" size="1">
        <option value="Active" <?php echo $row['TubeStatus']=="Active"?"selected=\"selected\"":""; ?> >Active</option>
        <option value="Inactive" <?php echo $row['TubeStatus']=="Inactive"?"selected=\"selected\"":""; ?> >Inactive</option>
        <option value="Removed" <?php echo $row['TubeStatus']=="Removed"?"selected=\"selected\"":""; ?> >Removed</option>
      </select>
    </td>
  </tr>
</table>

<h3>Notes</h3>
<textarea name="Notes" rows="2" cols="70" value="<?PHP echo $row['Notes']; ?>"><?PHP echo $row['Notes']; ?></textarea>
<p><input type="SUBMIT" value="Modify"> / <input type="RESET" value="Reset"> / <a href="index.html" >Main</a></p>
</form>
<?PHP
  mysql_free_result($manuf);
  mysql_free_result($result);
}
else if (isset($TubeID) && !empty($change)) {
  /*
    Step 2: Changes have been entered, now process them
  */
  $query = "UPDATE Tubes SET 
            HousingManufID=$HousingManufID, HousingModel=\"$HousingModel\", HousingSN=\"$HousingSN\", 
      InsertModel=\"$InsertModel\", InsertSN=\"$InsertSN\", InsertManufID=$InsManufID, 
      ManufDate=\"$ManufDate\", InstallDate=\"$InstallDate\", RemoveDate=\"$RemoveDate\",
      LFS=$LFS, SFS=$SFS, Status=\"$TubeStatus\", Notes=\"$Notes\" 
      WHERE TubeID=$TubeID";

  $result = mysql_query($query)
    or die ("<p>Unable to update: $query</p>\n");
  //echo "<p>$query</p>";

  echo "<h2>Record Updated</h2>\n";
  echo "<p>Tube $TubeID updated</p>\n";
}
?>
<form action="TubeModify.php" method="POST">
<P>Select a machine to modify
<?PHP
$tubes = mysql_query("select TubeID,concat_ws('-',Description,InsertSN) from Tubes,Machines where Machines.MachineID=Tubes.MachineID and Tubes.Status=\"Active\" and Machines.Status=\"Active\" order by Description");
echo listbox_field($tubes,"TubeID","");
?>
</p>
<p><input type="SUBMIT" value="Select"> / <input type="RESET" value="Reset"> / <a href="index.html" target="_top">Main</a></p>
</form>
<?PHP mysql_close() ?>

</body>
</html>
